<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2016-6-21
 * Func   后台首页
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$a = NoBadStr($_REQUEST['a']);
if($a == 'main')
{
    $today = strtotime(date('Y-m-d'));
	
	$num = [];
	
	//	今日注册量
	$tmp = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('user').' t LEFT JOIN '.Table('user_status').' u ON t.id = u.uid WHERE t.reg_time > '.$today.' AND u.upuid = '.$_uid);
	$num['useradd'] = intval($tmp['p']);
	
	//	总人数
	$tmp = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('user').' t LEFT JOIN '.Table('user_status').' u ON t.id = u.uid WHERE u.upuid = '.$_uid);
	$num['userall'] = intval($tmp['p']);
	
	//	今日投注
	$tmp = $db->getrow('SELECT SUM(t.money) AS p FROM '.Table('lottery_order_list').' t LEFT JOIN '.Table('user_status').' u ON t.uid = u.uid WHERE t.dateline > '.$today.' AND u.upuid = '.$_uid);
	$num['orderadd'] = round($tmp['p'],2);
	
	//	今日充值
	$tmp = $db->getrow('SELECT SUM(t.money) AS p FROM '.Table('user_money_recharge').' t LEFT JOIN '.Table('user_status').' u ON t.uid = u.uid WHERE t.status = 1 AND t.dateline > '.$today.' AND u.upuid = '.$_uid);
	$num['rechargeadd'] = round($tmp['p'],2);
	
	//	今日提现
	$tmp = $db->getrow('SELECT SUM(t.money) AS p FROM '.Table('user_money_cash').' t LEFT JOIN '.Table('user_status').' u ON t.uid = u.uid WHERE t.dateline > '.$today.' AND u.upuid = '.$_uid);
	$num['cashadd'] = round($tmp['p'],2);
	
	//	总返点
	$tmp = $db->getrow('SELECT SUM(money) AS p FROM '.Table('user_money_rebate').' WHERE uid = '.$_uid);
	$num['rebateall'] = round($tmp['p'],2);
	
	//	本次登录和上次登录
	$login = $db->getall('SELECT * FROM '.Table('agent_user_login').' WHERE username = \''.$_SESSION['agent']['username'].'\' AND status = 1 ORDER BY id DESC LIMIT 2');
	//	ip
	include_once(LIB_PATH.'class/Qqwry.class.php');
	$qqwry = new Qqwry();
	if($login[0])
	{
		$t2 = $qqwry->getlocation($login[0]['ip']);
		$login[0]['ip'] .= '('.$t2['country'].' '.$t2['area'].')';
	}
	if($login[1])
	{
		$t2 = $qqwry->getlocation($login[1]['ip']);
		$login[1]['ip'] .= '('.$t2['country'].' '.$t2['area'].')';
	}
	
	//	代理通知
	$notice = $db->getall('SELECT * FROM '.Table('agent_notice').' WHERE status = 1 ORDER BY id DESC LIMIT 5');

    $tpl->display('index/index_main');
    exit();
}

$tpl->display('index/index');

?>